<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/**
 * 68KB
 *
 * An open source knowledge base script
 *
 * @package		68kb
 * @author		68kb Dev Team
 * @copyright	Copyright (c) 2009, 68 Designs, LLC
 * @license		http://68kb.com/user_guide/license.html
 * @link		http://68kb.com
 * @since		Version 1.0
 */

// ------------------------------------------------------------------------

/**
 * book Model
 *
 * This class is used to handle the books data.
 *
 * @package		68kb
 * @subpackage	Models
 * @book	Models
 * @author		68kb Dev Team
 * @link		http://68kb.com/user_guide/overview/books.html
 * @version 	$Id: Book_model.php 89 2009-08-13 01:54:20Z suzkaw68 $
 */
class Book_model extends CI_model
{	
	/**
	 * Constructor
	 *
	 * @uses 	get_settings
	 * @return 	void
	 */
	function __construct()
	{
		parent::__construct();
		$this->load->database();
		log_message('debug', 'book Model Initialized');
	}
	
	// ------------------------------------------------------------------------
		
	/**
	* Delete book
	* 
	* @param	int $book_id The id of the book to delete.
	* @return	true on success.
	*/
	function delete_book($book_id)
	{
		$book_id=(int)trim($book_id);
		$this->db->delete('books', array('book_id' => $book_id)); 
		if ($this->db->affected_rows() > 0) 
		{
			$this->db->cache_delete_all();
			return true;
		} 
		else 
		{
			return false;
		}
	}
	
	// ------------------------------------------------------------------------
	
	/**
 	* Edit book
 	* 
 	* @param	array $data An array of data.
	* @uses 	format_uri
 	* @return	true on success.
 	*/
	function edit_book($book_id, $data)
	{	
	}
	
	// ------------------------------------------------------------------------
	
	/**
 	* Add book
 	* 
 	* @param	array 	$data An array of data.
	* @uses 	format_uri
 	* @return	mixed 	Id on success.
 	*/
	function add_book($data)
	{
	}
	
	
	// ------------------------------------------------------------------------
	
	/**
	 * Get book By ID.
	 *
	 * Get a single book from its id
	 *
	 * @access	public
	 * @param	int	the unique id
	 * @return	array
	 */
	function get_cat_by_id($id)
	{
		$id=(int)$id;
		$this->db->from('books')->where('cat_id', $id);
		$query = $this->db->get();
		$data = $query->row();
		$query->free_result();
		return  $data;
	}
	
	
	function getBookAll()
	{
		$this->db->from('books');
		$query = $this->db->get();
		
		return $query->result_array();
	}
	
	// ------------------------------------------------------------------------
	
	/**
	 * Get book Name By ID.
	 *
	 * Get a single book Name
	 *
	 * @access	public
	 * @param	int	the unique id
	 * @return	string
	 */
	function get_cat_name_by_id($id)
	{
		$this->db->select('cat_name')->from('books')->where('cat_id', $id);
		$query = $this->db->get();
		$data = $query->row();
		$query->free_result();
		return  $data->cat_name;
	}
	
}
	
/* End of file Book_model.php */
/* Location: ./upload/includes/application/models/Book_model.php */ 
